﻿<?php
@session_start();
include_once("../initial.php");
$DOCUMENT_ROOT=$_SERVER["DOCUMENT_ROOT"];
include_once(constant('PROJECT_DIR')."/logic/userLogic.php");
include_once(constant('PROJECT_DIR')."/logic/classLogic.php");
$LIST_NUMBER_PER_PAGE=10;
require_once("../checkLogin.php");
if($login==true)
{
		$smarty->assign("userId", $uid);
		$smarty->assign("unReadNum", $unReadNum);
}
//begin to read class
$ul = new userLogic();
$cl = new classLogic();

$action="";
if(isset($_POST['action']))
{
     $action = $_POST['action'];
}
else if(isset($_GET['action']))
{
     $action=$_GET['action'];
}
$note="";
switch($action)
{
			case "modifyUserPassword":
					$pass1 = $_POST['password1'];
					$pass2 = $_POST['password2'];
					if($pass1 != $pass2)
					{
							$note="两次输入的新密码不同，修改失败.";
							break;
					}
					$ul->update_user(array("passwd"=>md5($pass1)), $uid);
					break;
			case "modifyUserEmail":
					$email=$_POST['email'];
					$ul->update_user(array("email"=>$email), $uid);
					break;
			case "modifyUserPhone":
					$phone = $_POST['phone'];
					$ul->update_user(array("phone"=>$phone), $uid);
					break;
			case "modifyUserInfo":
					$info = $_POST['info'];
					$ul->update_user(array("info"=>$info), $uid);
					break;
}
$editUser = $ul->get_user(array("id"=>$uid));

//扩展用户班级名称
$uclassId = $editUser[0]['classid'];
$classInfo = $cl->get_class(array("id"=>$uclassId));
if(count($classInfo)<=0)
{
		$editUser[0]['classname']="不属于任何班级";
}
else
{
		$editUser[0]['classname']=$classInfo[0]['name'];
}
$smarty->assign("editUser", $editUser[0]);
$smarty->assign("note", $note);
$smarty->assign("menuSelected", "user");
$smarty->assign("projectUrl", constant('PROJECT_URL'));
$smarty->assign("currentUrl","user/user.php");
$smarty->display("user/user.html");
?>

